package logic

import (
	"baidu/baidurpc/baidurpc"
	"baidu/baidurpc/internal/svc"
	"baidu/modil/mysql"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBookLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookLogic {
	return &BookLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BookLogic) Book(in *baidurpc.BookRequest) (*baidurpc.BookResponse, error) {
	// todo: add your logic here and delete this line
	book := mysql.Book{
		Title:  in.Title,
		Text:   in.Text,
		UserId: in.UserId,
		Types:  in.Types,
	}
	mysql.DB.Debug().Create(&book)
	return &baidurpc.BookResponse{
		BookId: int64(book.ID),
	}, nil
}
